package com.woniu.core.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.core.entity.CoreTenderRecord;
import com.woniu.core.mapper.CoreTenderMapper;
import com.woniu.core.mapper.CoreTenderRecordMapper;
import com.woniu.core.service.CoreTenderRecordService;
import com.woniu.util.utils.HttpResult;
import com.woniu.util.utils.RequestResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CoreTenderRecordServiceImpl implements CoreTenderRecordService {
    @Autowired
    private CoreTenderRecordMapper coreTenderRecordMapper;
    @Autowired
    private CoreTenderMapper coreTenderMapper;

    @Override
    public HttpResult<?> auditCoreTender(Integer tenderId, Integer coreAuditResults) {
        coreTenderMapper.updateTenderCoreAuditResults(tenderId, coreAuditResults);
        coreTenderRecordMapper.addCoreTenderRecord(tenderId, coreAuditResults);
        return new HttpResult<>().ok();
    }

    @Override
    public HttpResult<?> selectCoreTenderRecord(RequestResult<CoreTenderRecord> param) {
        try {
            PageHelper.startPage(param.getPageNum(), param.getPageSize());
            List<CoreTenderRecord> records = coreTenderRecordMapper.selectCoreTenderRecord(param.getData());
            PageInfo<CoreTenderRecord> pageInfo = new PageInfo<>(records);
            return new HttpResult<>().ok(pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return new HttpResult<>().fail();
        }
    }
}
